package mume.android;

import android.app.Activity;
import android.app.AlertDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.google.zxing.MultiFormatReader;
import com.google.zxing.Reader;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;

public class TestApp extends Activity {
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		View scan1 = this.findViewById(R.id.Button01);
		scan1.setOnClickListener(handleClickScan1);
	}

	public final Button.OnClickListener handleClickScan1 = new Button.OnClickListener() {
		@Override
		public void onClick(View v) {
			Reader reader = new MultiFormatReader();
			Result result = null;
			Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.rhcp);
			RGBMonochromeBitmapSource source = new RGBMonochromeBitmapSource(bitmap);
			try {
				result = reader.decode(source);
				showDialog("Succes", result.getText());
			} catch (ReaderException e) {
				showDialog("ERROR","ReaderException");
			}
//
		}
	};

	private void showDialog(String title, String message) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setTitle(title);
		builder.setMessage(message);
		builder.setPositiveButton("OK", null);
		builder.show();
	}
}